package Engine.AIUGame
{
	public class AIGroup extends AIBasic
	{
		public var members:Array = [];
		
		public function AIGroup()
		{
			
		}
		
		public function add(obj:AIObject):void
		{
			var index:int = members.indexOf(obj);
			if((index < 0) || (index >= members.length))
			{
				members.push(obj);
				obj.visible = true;
			}
		}
		
		public function remove(obj:AIObject):void
		{
			var index:int = members.indexOf(obj);
			if((index < 0) || (index >= members.length))
			{
				return;
			}
			members.splice(index,1);
		}
		
		override public function update():void
		{
			var basic:AIObject;
			var i:uint = 0;
			while(i < members.length)
			{
				basic = members[i++] as AIObject;
				if((basic != null) && basic.exists && basic.active)
				{
					basic.preUpdate();
					basic.update();
					basic.postUpdate();
				}
			}
		}
		
		override public function draw():void
		{
			var basic:AIObject;
			var i:uint = 0;
			while(i < members.length)
			{
				basic = members[i++] as AIObject;
				if((basic != null) && basic.exists && basic.visible)
					basic.draw();
			}
		}
		
		
		public function get length():uint
		{
			return members.length;
		}
		
		
		
	}
}